-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/testing #81
base: main
Are you sure you want to change the base?
Feat/testing #81
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing here job @sofisdev !
I have added a couple of suggestions. Take a look at them and let me know what you think 😄
src/utils/jsonValidator.js
Outdated
questions: Joi.array() | ||
.required() | ||
.items( | ||
Joi.object({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be cool if this declaration would be in a separate file (maybe QuestionSchemas could fit) and reused on dependentQuestions instead of duplicating 😬
Also, I have read the README and it looks like there are different kind of questions with different properties. It would be amazing if each kind of question will have it own schema.
Something like this:
// baseQuestionSchema.js
const question = Joi.object({
// This way it can have recursive validations
dependentQuestion: Joi.array().items(Joi.lazy(() => question))
})
// checkBoxSchema.js
import questionSchema from './baseQuestionSchema.js'
const checkBoxSchema = questionSchema.append({
// checkBox specific properties
})
// questionsSchema.js
const questionsSchema = Joi.array().items(CheckBoxSchema, CountrySchema, InputSchema, ...etc)
// jsonValidator.js
questions: questionsSchema.required()
This way, each Question update would be independent of the others and they would be easier to test 😬
What do you believe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm loving this approach, so well structured!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed the approach since Joi.lazy()
and Joi.link()
were not a solution, however I still have a bug I'm currently trying to solve
src/builder.js
Outdated
@@ -36,6 +37,7 @@ const FormBuilder = ({ | |||
isoCode, | |||
...props | |||
}) => { | |||
console.log(schema.validate(form)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be better if instead of logging an error it will throw in case the schema is incorrect, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely, this was only temporary until we decide what would be rendered in case of error
src/utils/jsonValidator.js
Outdated
id: Joi.string().required() | ||
}) | ||
|
||
export default schema |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cause this file is a jsonValidator, what if instead of returning Joi's schemas it returns a validate function which uses Joi.validate. This way we'll be using a Joi's wrapper and we could change the library when required.
Something like this:
const validate = (json) => {
const result = schema.validate(json);
if (result.error) {
throw new Error(`Validation errors: ${result.error}`)
}
return result.value
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice job 😄 💥
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @sofisdev I 've left some comments that would be nice to go through them. :)
@@ -181,6 +181,7 @@ const App = () => { | |||
isoCode='ES' | |||
onLinkOpen={onLinkOpen} | |||
isLoading={isLoading} | |||
validateJSON |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid truly expressions. The reason behind this is if I'm passing to boolean expressions let say validateJSON
and notValidateJSON
I would not know the behavior without going to the implementation details. Think components as functions, passing booleans as arguments makes the function really hard to maintain. I'd use some sort of state handling @sofisdev
window.MutationObserver = MutationObserver | ||
|
||
let component = null | ||
let mockHandler = null | ||
// const isLoading = false | ||
let loaderc = false | ||
// function useLoading(isLoading) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove comments
...props | ||
}) => { | ||
const useFormObj = useForm({ defaultValues: { formatDate: '' } }) | ||
const { errors } = useFormObj | ||
|
||
validateJSON && validate(form) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we handle this with try and catch?
Type:
What's the focus of this PR:
FormBuilder
component